#ifndef __IIC_H_
#define __IIC_H_

#include <STC8G.H>
#include <basic.h>
typedef void (*i2c_port_controler_t)( bool isHigh);
typedef bool (*i2c_port_read_t)();

typedef struct
{
    i2c_port_controler_t scl_ctrl;
    i2c_port_controler_t sda_ctrl;
    i2c_port_read_t sda_read;

    int8_t addr;
} i2c_handle_t;

void i2c_start(i2c_handle_t *handler);
void i2c_stop(i2c_handle_t *handler);
void i2c_ack(i2c_handle_t *handler);
uint8_t i2c_wait_ack_fail(i2c_handle_t *handler);
void i2c_write_byte_(i2c_handle_t *handler, uint8_t dat);

// standard function
bool i2c_begin_transmission(i2c_handle_t *handler);
bool i2c_end_transmission(i2c_handle_t *handler);
bool i2c_write_byte(i2c_handle_t *handler, uint8_t dat);
uint16_t i2c_write(i2c_handle_t *handler, uint8_t *dat, uint16_t len);

uint8_t i2c_read_byte(i2c_handle_t *handler, uint8_t ack);

int8_t i2c_probe(i2c_handle_t *handler, uint8_t DevAddress);
int8_t i2c_scan(i2c_handle_t *handler);

#endif // IIC_H